package com.canal.admin.entity;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

/**
 * @author Administrator
 * @description
 * @date 2019年03月17 13:55
 */
public class TokenBasedAuthentication extends AbstractAuthenticationToken {

    private UserDetails principel;

    private String credentials;

    private String token;

    public TokenBasedAuthentication(String token) {
        super(Collections.emptyList());
        this.token = token;
        super.setAuthenticated(false);
    }

    public TokenBasedAuthentication(UserDetails principel, String token,
                                    Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principel = principel;
        this.token = token;
        super.setAuthenticated(true);
    }

    @Override
    public void setDetails(Object details) {
        super.setDetails(details);
        this.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return credentials;
    }

    @Override
    public Object getPrincipal() {
        return principel;
    }

    public String getToken() {
        return token;
    }

    @Override
    public String toString() {
        return "TokenBasedAuthentication{" +
                "principel=" + principel +
                ", credentials='" + credentials + '\'' +
                ", token='" + token + '\'' +
                '}';
    }
}
